package org.opensource.openapi3doc;

import static springfox.documentation.spi.DocumentationType.OAS_30;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spring.web.plugins.Docket;

//@EnableSwagger2
@SpringBootApplication
public class OpenAPI3Application implements CommandLineRunner {
    private static Logger logger = LoggerFactory.getLogger(OAS3Yaml.class);

    @Autowired
    private Environment env;

    @Override
    public void run(String... args) throws Exception {
        if (env != null) {
            logger.info("YAML ROOT: " + env.getProperty("spring.web.resources.static-locations"));
        } 
    } 

    public static void main(String[] args) {
        SpringApplication.run(OpenAPI3Application.class, args);
    }

    @Bean
    public Docket swagger() {
        return new Docket(OAS_30)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build();
    }

}
